package operations;

import agent.BoatStates;
import agent.State;

public class Unload implements Operation{

	@Override
	public State exec(State nod) {
		if (!validOperation(nod))
			return null;
		State ret = nod.dupe();
		switch (ret.getBoatPassanger()) {
		case cabage:
			if (ret.isBoatLeft())
				ret.setCabadgeLeft(true);
			else
				ret.setCabadgeRight(true);
			break;
		case wolf:
			if (ret.isBoatLeft())
				ret.setWolfLeft(true);
			else
				ret.setWolfRight(true);
			break;
		case goat:
			if (ret.isBoatLeft())
				ret.setGoatLeft(true);
			else
				ret.setGoatRight(true);
			break;
		default:
			break;
		}
		
		ret.setBoatPassanger(BoatStates.empty);
		return ret;
	}

	@Override
	public boolean validOperation(State nod) {
		if (nod.getBoatPassanger()==BoatStates.empty)
			return false;
		return true;
	}

}
